home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / infosrvr / dev / scott / WWW / NextStep / Implementation / old / HTAccess.c < prev    next >
C/C++ Source or Header  |  1991-06-27  |  2KB  |  86 lines

  1. /*        Access Manager                    HTAccess.c
  2. **        ==============
  3. */
  4.  
  5. #include "HTParse.h"
  6. #include "HTUtils.h"
  7. #include "WWW.h"
  8. #include "HTFTP.h"
  9. #include "HTTP.h"
  10. #include "HTFile.h"
  11. #include <errno.h>
  12. #include <stdio.h>
  13.  
  14. #ifdef EXPLICIT_INCLUDES
  15. #ifndef vms
  16. #include <string.h>
  17. #include <sys/file.h>
  18.  
  19. #else    /* VMS */
  20. #include <errno.h>
  21. #include file
  22. #include unixio
  23. #endif    /* VMS */
  24.  
  25. #else    /* not explicit includes */
  26. #include "tcp.h"
  27. #endif
  28.  
  29.  
  30. /*    Open a file descriptor for a document
  31. **    -------------------------------------
  32. **
  33. ** On entry,
  34. **    addr        must point to the fully qualified hypertext reference.
  35. **
  36. ** On exit,
  37. **    returns        <0    Error has occured.
  38. **            >=0    Value of file descriptor or socket to be used
  39. **                 to read data.
  40. **    *pFormat    Set to the format of the file, if known.
  41. **            (See WWW.h)
  42. **
  43. */
  44. #ifdef __STDC__
  45. int HTOpen(const char * addr, WWW_Format * pFormat)
  46. #else
  47. int HTOpen(addr, pFormat)
  48.     char     * addr;
  49.     WWW_Format    * pFormat;
  50. #endif
  51. {
  52.     char * access=0;    /* Name of access method */
  53.     
  54.     access =  HTParse(addr, "file:", PARSE_ACCESS);
  55.     if (0==strcmp(access, "file")) {
  56.         return HTOpenFile(addr, pFormat);
  57.  
  58.     } else if (0==strcmp(access, "http")) {
  59.         free(access);
  60.     *pFormat = WWW_HTML;
  61.     return HTTP_Get(addr);
  62.     
  63.     } else if (0==strcmp(access, "news")) {
  64.         printf("HTAccess: Sorry, Internet news not integrated yet.\n");
  65.     }
  66.  
  67.     printf("HTAccess: Unknown access `%s'\n", access);
  68.     free(access);
  69.     return -1;
  70. }
  71.  
  72.  
  73. /*    Close socket opened for reading a file
  74. **    --------------------------------------
  75. **
  76. */
  77. #ifdef __STDC__
  78. PUBLIC int HTClose(int soc)
  79. #else
  80. PUBLIC int HTClose(soc)
  81.     int soc;
  82. #endif
  83. {
  84.     return HTFTP_close_file(soc);
  85. }
  86.